﻿<%@ page contentType="text/html; charset=utf-8"%>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<%@ taglib uri="http://www.springframework.org/tags" prefix="spring"%>
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<%@taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<c:set var="basePath" value="${pageContext.request.contextPath}"/>
<script src="${basePath}/js/jquery/jquery.form.js"></script>
<div id="createDialog" class="crudDialog">
	<form id="createForm" method="post" enctype="multipart/form-data">
		<div class="form-group">
			<%--<label for="name">主题</label>--%>
			<input id="name" type="text" class="form-control" name="subject" maxlength="250" placeholder="主题">
		</div>
		<div class="form-group">
			<%--<label for="stumitter">提交人</label>--%>
			<input id="stumitter" type="text" class="form-control" name="stumitter" maxlength="20" placeholder="提交人">
		</div>
		<div class="form-group">
		<%--	<label for="file"></label>--%>
			<input id="file" type = "file" class="form-control" name="fileName" maxlength="20">
		</div>
		<div class="form-group text-right dialog-buttons">
			<a class="waves-effect waves-button" href="javascript:;" onclick="createSubmit();">保存</a>
			<a class="waves-effect waves-button" href="javascript:;" onclick="createDialog.close();">取消</a>
		</div>
	</form>
	<div class="progress">
		<div class="bar"></div >
		 <div class="percent">0%</div >
	</div>
	<div id="status"></div>
</div>
<script>
$(function(){
    $("name").val("");
    $("stumitter").val("");

});


function createSubmit() {
	var stuSubject = $("#name").val();
	var stumitter = $("#stumitter").val();

	if($.trim(stuSubject) == ""){
		reConfirm("主题不能为空！");
		return;
	}
	if($.trim(stumitter) == ""){
		reConfirm("提交人不能为空！");
		return;
	}
	var bar = $(".bar");
	var percent = $(".percent");
	var status = $("#status");
	var form = new FormData(document.getElementById("createForm"));
	$.ajax({
		type:"POST",
		url:"${basePath}/manage/studymanage/createAvtive",
		processData:false,
		contentType:false,
		data:form,
		beforeSend:function(){
			status.empty();
			var percentVal = '0%';
			bar.width(percentVal);
			percent.html(percentVal);
		},
		uploadProgress: function(event, position, total, percentComplete) {//上传的过程
			//position 已上传了多少
			//total 总大小
			//已上传的百分数
			var percentVal = percentComplete + '%';
			bar.width(percentVal)
			percent.html(percentVal);
			//console.log(percentVal, position, total);
		},
		success:function (data) {
			reConfirm(data.message);
			if (data.code === 1){
				createDialog.close();
				$table.bootstrapTable("refresh");
			}

		},
		error:function (error) {
			reConfirm(error.message)
		}
	})

}
function reConfirm(content) {
	$.confirm({
		title: "提示",
		content: content,
		autoClose: 'cancel|3000',
		backgroundDismiss: true,
		buttons: {
			cancel: {
				text: '确定',
				btnClass: 'waves-effect waves-button'
			}
		}
	});
}
</script>